<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label">接尸日期</label>
        <div class="layui-inline">
          <el-radio-group v-model="selectDataEixend.regDateValue" @change="btnSearch">
            <el-radio-button :label="DateSelectMode.now" class="radio">当日</el-radio-button>
            <el-radio-button :label="DateSelectMode.future" class="radio">以后</el-radio-button>
            <el-radio-button :label="DateSelectMode.all" class="radio">全部</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">业务状态</label>
        <div class="layui-inline">
          <el-radio-group v-model="selectDataEixend.regIchValue" @change="btnSearch">
            <el-radio-button :label="IchAll" class="radio">全部</el-radio-button>
            <el-radio-button :label="IchValue" class="radio">在冷藏</el-radio-button>
            <el-radio-button :label="UnIchValue" class="radio">其他</el-radio-button>
          </el-radio-group>
        </div>
      </div>
    </div>
    <el-tabs v-model="activeName" type="card" style="margin-top:10px;">
       <el-tab-pane style="height:500px" label="查询条件" name="search">
           <div class="header-form">
                <div class="layui-inline">
                    <label class="layui-form-label">数据来源</label>
                    <div class="layui-input-inline">
                    <el-select v-model="selectDataEixend.reglyvalue" filterable @change="btnSearch">
                        <el-option v-for="item in jpmform" :key="item.Value" :label="item.Text" :value="item.Value">
                        </el-option>
                    </el-select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">业务编号</label>
                    <div class="layui-inline">
                    <el-input style="width:200px" v-model="selectData.RegbussnumLike" placeholder="请输入业务编号" @keydown.enter.native="btnSearch"></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">证件号码</label>
                    <div class="layui-inline">
                    <el-input style="width:200px" v-model="selectData.RegCardnoEquals" placeholder="请输入证件号码" @keydown.enter.native="btnSearch"></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">逝者姓名</label>
                    <div class="layui-inline">
                    <el-input style="width:200px" v-model="selectData.RegnameLike" placeholder="请输入逝者姓名" @keydown.enter.native="btnSearch"></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">灵堂</label>
                    <div class="layui-inline">
                        <el-select v-model="selectData.LINNAMEEquals" filterable @change="btnSearch">
                            <!-- 按照名称查找 -->
                            <el-option v-for="item in mourningOptions" :key="item.LINID" :label="item.LINNAME" :value="item.LINNAME">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">礼厅</label>
                    <div class="layui-inline">
                        <el-select v-model="selectData.MEMNAMEEquals" filterable @change="btnSearch">
                            <!-- 按照名称查找 -->
                            <el-option v-for="item in memorialOptions" :key="item.MEMID" :label="item.MEMNAME" :value="item.MEMNAME">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">冰柜</label>
                    <div class="layui-inline">
                        <el-select v-model="selectData.ICENOEquals" filterable @change="btnSearch">
                            <!-- 按照名称查找 -->
                            <el-option v-for="item in iceOptions" :key="item.ICEID" :label="item.ICENAME" :value="item.ICENAME">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">火化日期</label>
                    <div class="layui-inline">
                        <el-date-picker style="width:200px" v-date v-model="selectData.RegAppointDateGreaterAndEquals" type="date" placeholder="选择日期范围" >
                        </el-date-picker>
                        <el-date-picker style="width:200px" v-date v-model="selectData.RegAppointDateLessAndEquals" type="date" placeholder="选择日期范围">
                        </el-date-picker>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-inline">
                        <el-input style="width:290px" v-model="selectData.REGREMARKLike" placeholder="请输入备注" @keydown.enter.native="btnSearch"></el-input>
                    </div>
                </div>
                <br>
                <div style="width:100%;text-align:center;margin-top:20px;">
                    <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
                    <el-button @click="btnRepeat">重置</el-button>
                </div>
            </div>
        </el-tab-pane>
        <el-tab-pane label="查询结果" name="results">
            <div style="margin-top:10px;">
                <ul class="toolList">
                    <li>
                    <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button>
                    </li>
                    <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                    <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                    </li>
                </ul>
            </div>
            <dataTable :headList="headList" :dataList="dataList" :hiddenColumn="hiddenColumn" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
            
        </el-tab-pane>
    </el-tabs>
    <!-- <div style="margin-top:10px;">
      <ul class="toolList">
        <li>
          <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button>
        </li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :hiddenColumn="hiddenColumn" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable> -->
    <mainmodel ref="models" @refreshData="getData"></mainmodel>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
<script>
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { manage } from "@/mixins/managePage.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import mainmodel from "./InternalDutyMain";
import { DATESELECTMODE } from "@/const/const.js";
import { ORDER } from "@/const/orderConst.js";
const MODIFY = "新增";
const DELETE = "删除";
const Detail = "详情";
const IchAll = "0";
const IchValue = "1";
const UnIchValue = "2";

export default {
    name: "numBand",
    mixins: [manage],
    data() {
        return {
            selectData: {
                RegdateEquals: null,
                RegcurstatusEquals: null,
                RegbussnumLike: null,
                RegCardnoEquals: null,
                RegnameLike: null,
                RegcurstatusUnEquals: "C",
                RegformidEquals: null,
                RegdateGreater: null,
                RegdateOrRegCremationdate: null,
                RegAppointDateGreaterAndEquals: null,
                RegAppointDateLessAndEquals: null,
                MEMNAMEEquals:null,
                LINNAMEEquals:null,
                ICENOEquals:null,
                REGREMARKLike:null,
            },
            selectDataEixend: {
                regDateValue: null,
                regIchValue: null,
                reglyvalue: null
            },
            DateSelectMode: DATESELECTMODE,
            IchAll: IchAll,
            IchValue: IchValue,
            UnIchValue: UnIchValue,
            regValue: null,
            unCome: "A",
            all: null,
            jpmform: [],
            hiddenColumn: false,
            ischangered: null,
            ischangnb: null,
            activeName:'results',
            iceOptions:[],
            memorialOptions:[],
            mourningOptions:[],
        };
    },
    methods: {
        btnShow(btn) {
            switch (btn) {
                case MODIFY:
                case DELETE:
                    if (this.currentRow) return true;
                    break;
                case Detail:
                    return this.currentRow != null;
                    break;
                default:
            }
        },
        //获取电话预约数据
        getData() {
            let selectData = JSON.parse(JSON.stringify(this.selectData));
            if (!this.selectData.RegbussnumLike) {
                selectData.RegbussnumLike = null;
            }
            if (!this.selectData.RegCardnoEquals) {
                selectData.RegCardnoEquals = null;
            }
            if (!this.selectData.RegbarnoEquals) {
                selectData.RegbarnoEquals = null;
            }
            if (!this.selectData.RegnameLike) {
                selectData.RegnameLike = null;
            }
            if(selectData.RegAppointDateGreaterAndEquals) {
                selectData.RegAppointDateGreaterAndEquals = formatDate(selectData.RegAppointDateGreaterAndEquals, "yyyyMMdd" );
            } 
            if(selectData.RegAppointDateLessAndEquals) {
                selectData.RegAppointDateLessAndEquals = formatDate(selectData.RegAppointDateLessAndEquals, "yyyyMMdd" );
            } 
            let data = {
                PageIndex: this.pageOrder.currentPage,
                PageSize: this.pageOrder.pageSize,
                OrderBy: this.pageOrder.orderType,
                OrderByType: this.pageOrder.orderSort,
                Data: selectData
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Internalduty.Query,
                res => {
                    this.activeName = 'results'
                    this.dataList = res.data.content.OutData;
                    this.pageOrder.totalNum = res.data.content.RecordCount;
                    this.dataList.forEach(data => {
                        data.CDHACTUALDATEDESC = data.CDHACTUALDATEDESC.substring(0, 16);
                        data.REGCREMATIONDATE = data.REGCREMATIONDATE.substring(0, 16);
                    });
                    this.$nextTick(function() {
                        let rows = document.getElementsByClassName("el-table__row");
                        if(this.ischangered){
                            this.dataList.forEach((item,index) => {
                                rows[index].style.color = '#606266';
                                if(item.REGCRETYPE === 'A'){
                                    rows[index].style.color = 'red';
                                }
                            });
                        };
                        if(this.ischangnb){
                            this.dataList.forEach((item,index) => {
                                rows[index].style.color = '#606266';
                                if(item.REGCRETYPE === 'A'||item.REGCRETYPE === 'C'){
                                    rows[index].style.color = '#007eff';
                                }
                                if(item.REGCRETYPE === 'D'){
                                    rows[index].style.color = 'red';
                                }
                            });
                        };
                    });
                }
            );
        },
        //获取表头
        getColumns() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Column.GetInternaldutyColumns,
                res => {
                    this.headList = res.data.content;
                }
            );
        },
         //获取来源数据
        getjpmform() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Registration.GetJPMFORM,
                res => {
                    this.jpmform = res.data.content;
                    this.jpmform.unshift({ Text: "全部", Value: null });
                }
            );
        },

        //功能操作
        operate(order) {
            this.order = order;
            switch (this.order) {
                case MODIFY:
                    this.$refs.models.open(
                        this.order,
                        this.currentRow.REGID,
                        this.currentRow.REGCURSTATUS
                    );
                    break;
                case DELETE:
                    // this.$refs.models.open(this.order);
                    this.delete();
                    break;
                case Detail:
                    this.$refs.models.open(this.order, this.currentRow);
                    break;
                default:
            }
        },
        //删除
        delete() {
            var data = {
                REGID: this.currentRow.REGID
            };
            this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Internalduty.Delete,
                        res => {
                            this.getData();
                            this.$message({
                                message: "删除数据成功！",
                                type: "success"
                            });
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除"
                    });
                });
        },
        initSeachdata() {
            this.regValue = this.unCome;
        },
        //查询条件重置
        btnRepeat() {
            Object.assign(this.$data.selectData,this.$options.data().selectData);
            if (this.isall === false) {
                this.selectDataEixend.regDateValue = DATESELECTMODE.now;
                this.selectData.RegdateOrRegCremationdate = formatDate(
                    new Date(),
                    "yyyyMMdd"
                );
                this.selectDataEixend.regIchValue = this.UnIchValue;
                this.selectData.RegcurstatusUnEquals = "C";
            } else {
                this.selectDataEixend.regDateValue = DATESELECTMODE.all;
                this.selectDataEixend.regIchValue = this.UnIchValue;
            }
            this.selectDataEixend.reglyvalue = null;
            this.getData();
        }
    },
    components: {
        dataTable,
        mainmodel
    },
    created() {
        apiBase.DoService({},apiBase.getApiAdress().Param.GetIsDataTableReddening,res => {
            this.ischangered = res.data.content; 
        });
        apiBase.DoService({},apiBase.getApiAdress().Param.GetIsCreChangeRed,res => {
            this.ischangnb = res.data.content; 
        });
        // 冰柜
        apiBase.DoService({},apiBase.getApiAdress().IceUse.QueryIce,res => {
            this.iceOptions = res.data.content; 
        });
        // 礼厅
        apiBase.DoService({},apiBase.getApiAdress().MemorialUse.QueryMemorial,res => {
            this.memorialOptions = res.data.content; 
        });
        // 灵堂
        apiBase.DoService({},apiBase.getApiAdress().MourningUse.QueryMourning,res => {
            this.mourningOptions = res.data.content; 
        });
        this.getColumns();
        this.getData();
        this.getjpmform();
    },
    mounted() {
        this.initSeachdata();
        this.selectDataEixend.regDateValue = DATESELECTMODE.all;
        this.selectDataEixend.regIchValue = this.UnIchValue;
    },
    watch: {
        regValue: function(val) {
            this.selectData.RegcurstatusEquals = null;
            switch (val) {
                case this.unCome:
                    this.selectData.RegcurstatusEquals = "A";
                    break;
                case this.all:
                    this.selectData.RegcurstatusEquals = null;
                    break;
                default:
                    break;
            }
        },
         "selectDataEixend.regDateValue": function(val) {
            this.selectData.RegdateGreater = null;
            this.selectData.RegdateOrRegCremationdate = null;
            switch (val) {
                case DATESELECTMODE.now:
                    this.selectData.RegdateOrRegCremationdate = formatDate(
                        new Date(),
                        "yyyyMMdd"
                    );
                    break;
                case DATESELECTMODE.future:
                    this.selectData.RegdateGreater = formatDate(
                        new Date(),
                        "yyyyMMdd"
                    );
                    break;
                default:
                    break;
            }
        },
        "selectDataEixend.regIchValue": function(val) {
            this.selectData.RegcurstatusEquals = null;
            this.selectData.RegcurstatusUnEquals = null;
            switch (val) {
                case IchValue:
                    this.selectData.RegcurstatusEquals = "C";
                    break;
                case UnIchValue:
                    this.selectData.RegcurstatusUnEquals = "C";
                    break;
                case IchAll:
                   
                    break;
                default:
                    break;
            }
        },
        "selectDataEixend.reglyvalue": function(val) {
            this.selectData.RegformidEquals = val;
            this.getData();
        },
    }
};
</script>
